<?php

class records_center_helper
{

    //根据订单ID列表获取订单相关的商品统计信息
    public static function get_goods_message($order_list = "") {
        //总件数
        $total_cartons = "";
        //总金额
        $aggregate_amount = "";
        //散装爆米花
        $in_bulk_popcorn = array();
        //罐装爆米花
        $canning_popcorn = array();
        //散装薯条
        $chips = array();
        //原料（影院专用）
        $raw_material = array();
        //纸杯
        $cups = array();
        //设备
        $device = array();
        //其他物料
        $unclassified_stores = array();
        //新品
        $new_product = array();
        foreach ($order_list as $k => $v) {
            $filter['order_id'] = $v;
            $order_relation_list = _model('order_relation')->getList($filter);
            if (empty($order_relation_list)) {
                unset($order_relation_list);
                continue;
            }
            //print_r($order_relation_list);exit;
            $total_cartons[] = $order_relation_list[0]['goods_num'];
            $aggregate_amount[] = $order_relation_list[0]['real_price'];
            //散装
            if (in_array($order_relation_list[0]['goods_id'], array_flip(records_center_config::$in_bulk_popcorn))) {
                $in_bulk_popcorn[] = $order_relation_list;
            }
            //罐装爆米花
            if (in_array($order_relation_list[0]['goods_id'], array_flip(records_center_config::$hard_canning_popcorn_100)) ||
                in_array($order_relation_list[0]['goods_id'], array_flip(records_center_config::$hard_canning_popcorn_130)) ||
                in_array($order_relation_list[0]['goods_id'], array_flip(records_center_config::$hard_canning_popcorn_150)) ||
                in_array($order_relation_list[0]['goods_id'], array_flip(records_center_config::$mild_canning_popcorn_55)) ||
                in_array($order_relation_list[0]['goods_id'], array_flip(records_center_config::$mild_canning_popcorn_90)) ||
                in_array($order_relation_list[0]['goods_id'], array_flip(records_center_config::$mild_canning_popcorn_120))
            ) {
                $canning_popcorn[] = $order_relation_list;
            }
            //散装薯条
            if (in_array($order_relation_list[0]['goods_id'], array_flip(records_center_config::$chips))) {
                $chips[] = $order_relation_list;
            }
            //原料（影院专用）
            if (in_array($order_relation_list[0]['goods_id'], array_flip(records_center_config::$raw_material))) {
                $raw_material[] = $order_relation_list;
            }
            //纸杯
            if (in_array($order_relation_list[0]['goods_id'], array_flip(records_center_config::$cups))) {
                $cups[] = $order_relation_list;
            }
            //设备
            if (in_array($order_relation_list[0]['goods_id'], array_flip(records_center_config::$in_bulk_device)) ||
                in_array($order_relation_list[0]['goods_id'], array_flip(records_center_config::$cinema_device))
            ) {
                $device[] = $order_relation_list;
            }
            //其他物料
            if (in_array($order_relation_list[0]['goods_id'], array_flip(records_center_config::$unclassified_stores))) {
                $unclassified_stores[] = $order_relation_list;
            }
            //新品
            if (in_array($order_relation_list[0]['goods_id'], array_flip(records_center_config::$new_product))) {
                $new_product[] = $order_relation_list;
            }
        }
        //散装数量
        $in_bulk_popcorn_goods_num = array();
        //散装价格
        $in_bulk_popcorn_real_price = array();
        foreach ($in_bulk_popcorn as $k => $v) {
            $in_bulk_popcorn_goods_num[] = $v[0]['goods_num'];
            $in_bulk_popcorn_real_price[] = $v[0]['real_price'];
        }

        //罐装数量
        $canning_popcorn_goods_num = array();
        //罐装价格
        $canning_popcorn_real_price = array();
        foreach ($canning_popcorn as $k => $v) {
            $canning_popcorn_goods_num[] = $v[0]['goods_num'];
            $canning_popcorn_real_price[] = $v[0]['real_price'];
        }

        //散装薯条数量
        $raw_material_goods_num = array();
        //散装薯条价格
        $raw_material_real_price = array();
        foreach ($raw_material as $k => $v) {
            $raw_material_goods_num[] = $v[0]['goods_num'];
            $raw_material_real_price[] = $v[0]['real_price'];
        }

        //原料数量
        $chips_goods_num = array();
        //原料价格
        $chips_real_price = array();
        foreach ($chips as $k => $v) {
            $chips_goods_num[] = $v[0]['goods_num'];
            $chips_real_price[] = $v[0]['real_price'];
        }

        //纸杯数量
        $cups_goods_num = array();
        //纸杯价格
        $cups_real_price = array();
        foreach ($cups as $k => $v) {
            $cups_goods_num[] = $v[0]['goods_num'];
            $cups_real_price[] = $v[0]['real_price'];
        }

        //设备数量
        $device_goods_num = array();
        //设备价格
        $device_real_price = array();
        foreach ($device as $k => $v) {
            $device_goods_num[] = $v[0]['goods_num'];
            $device_real_price[] = $v[0]['real_price'];
        }

        //其他物料数量
        $unclassified_stores_goods_num = array();
        //其他物料价格
        $unclassified_stores_real_price = array();
        foreach ($unclassified_stores as $k => $v) {
            $unclassified_stores_goods_num[] = $v[0]['goods_num'];
            $unclassified_stores_real_price[] = $v[0]['real_price'];
        }

        //新品数量
        $new_product_goods_num = array();
        //新品价格
        $new_product_real_price = array();
        foreach ($new_product as $k => $v) {
            $new_product_goods_num[] = $v[0]['goods_num'];
            $new_product_real_price[] = $v[0]['real_price'];
        }
        if (!$total_cartons) {
            $total_cartons = array();
        }
        if (!$aggregate_amount) {
            $aggregate_amount = array();
        }
        $nationwide = array();
        $nationwide['total_cartons'] = array_sum($total_cartons);
        $nationwide['aggregate_amount'] = array_sum($aggregate_amount);
        $nationwide['in_bulk_popcorn_goods_num'] = array_sum($in_bulk_popcorn_goods_num);
        $nationwide['in_bulk_popcorn_real_price'] = array_sum($in_bulk_popcorn_real_price);
        $nationwide['canning_popcorn_goods_num'] = array_sum($canning_popcorn_goods_num);
        $nationwide['canning_popcorn_real_price'] = array_sum($canning_popcorn_real_price);
        $nationwide['chips_goods_num'] = array_sum($chips_goods_num);
        $nationwide['chips_real_price'] = array_sum($chips_real_price);
        $nationwide['raw_material_goods_num'] = array_sum($raw_material_goods_num);
        $nationwide['raw_material_real_price'] = array_sum($raw_material_real_price);
        $nationwide['cups_goods_num'] = array_sum($cups_goods_num);
        $nationwide['cups_real_price'] = array_sum($cups_real_price);
        $nationwide['device_goods_num'] = array_sum($device_goods_num);
        $nationwide['device_real_price'] = array_sum($device_real_price);
        $nationwide['unclassified_stores_goods_num'] = array_sum($unclassified_stores_goods_num);
        $nationwide['unclassified_stores_real_price'] = array_sum($unclassified_stores_real_price);
        $nationwide['new_product_goods_num'] = array_sum($new_product_goods_num);
        $nationwide['new_product_real_price'] = array_sum($new_product_real_price);
        return $nationwide;

    }

    public static function get_goods_message_by_goods_id($order_id_list, $id = "") {
        $goods_num = array();
        $real_price = array();
        foreach ($order_id_list as $k => $v) {
            $filter['order_id'] = $v;
            $order_relation_list = _model('order_relation')->getList($filter);
            if (empty($order_relation_list)) {
                unset($order_relation_list);
                continue;
            }

            if ($order_relation_list[0]['goods_id'] == $id) {
                $goods_num[] = $order_relation_list[0]['goods_num'];
                $real_price[] = $order_relation_list[0]['real_price'];
            }
        }

        $goods_message = array();
        $goods_message['goods_id'] = $id;
        $goods_message['goods_num'] = array_sum($goods_num);
        $goods_message['real_price'] = array_sum($real_price);
        return $goods_message;
    }

    public static function get_second_goods_message_by_goods_id($order_id_list, $id = "", $goods_name = "") {
        $goods_num = array();
        $real_price = array();
        foreach ($order_id_list as $k => $v) {
            $filter['order_id'] = $v;
            $order_relation_list = _model('order_relation')->getList($filter);
            if (empty($order_relation_list)) {
                unset($order_relation_list);
                continue;
            }

            if (in_array($order_relation_list[0]['goods_id'], array_flip(records_center_config::$$id))) {
                $goods_num[] = $order_relation_list[0]['goods_num'];
                $real_price[] = $order_relation_list[0]['real_price'];
            }
        }

        $goods_message = array();
        $goods_message['sku_category_id'] = $id;
        $goods_message['goods_name'] = $goods_name;
        $goods_message['goods_num'] = array_sum($goods_num);
        $goods_message['real_price'] = array_sum($real_price);
        return $goods_message;
    }
}

?>